﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XiaoYuStock.Model.Entities
{
    public class HistoryDataModel
    {

        public int Id { get; set; }


        public string ShareCode { get; set; }

        public string ShareName { get; set; }


        public string CurrentDate { get; set; }


        public decimal OpenAmount { get; set; }

        public decimal CloseAmout { get; set; }


        public decimal MaxAmount { get; set; }


        public decimal MinAmount { get; set; }


        public long TradeCount { get; set; }


        public decimal TradeAmount { get; set; }

        /// <summary>
        /// 交易时间
        /// </summary>
        public DateTime TradeTime { get; set; }

        public string WeekDay { get; set; }

        /// <summary>
        /// 比率
        /// </summary>
        public decimal? TradeRate { get; set; }

        /// <summary>
        /// 差价
        /// </summary>
        public decimal? DiffPrice { get; set; }

        /// <summary>
        /// 昨日收盘价
        /// </summary>
        public decimal? YesterdayCloseAmount { get; set; }

        /// <summary>
        /// 流通股
        /// ltg
        /// </summary>
        public decimal Ltg { get; set; }

        /// <summary>
        /// 每股收益
        /// </summary>
        public decimal? Income { get; set; }

        /// <summary>
        /// 净资产
        /// </summary>
        public decimal? Mgjzc { get; set; }

        /// <summary>
        /// 振幅
        /// 计算方法：
        /// （最高价-最低价）/昨日收盘价*100 %
        /// </summary>
        public decimal Amplitude
        {

            get
            {

                if (this.YesterdayCloseAmount.HasValue && this.YesterdayCloseAmount.Value > 0)
                {
                    return (this.MaxAmount - this.MinAmount) / this.YesterdayCloseAmount.Value;
                }
                else
                {
                    return 0;
                }
            }
        }

        /// <summary>
        /// 换手率
        /// 计算方法
        /// data.ltg) ? ((成交量/data.ltg*100)%) :" --"
        /// </summary>
        public decimal TurnoverRate
        {
            get
            {
                if (this.Ltg > 0)
                {
                    return (this.TradeCount / this.Ltg) * 100;
                }
                else
                {
                    return 0;
                }

            }
        }

        /// <summary>
        /// 市盈率
        /// 
        /// if(收盘价/data.mgsy<0)
        ///     {
        ///           return "亏损";
        ///
        ///     }
        ///     else
        ///     {    
        ///  if(data.mgsy !=0)
        ///  {
        ///               return (收盘价/data.mgsy).toFixed(2));
        ///   }
        ///  else{
        ///   return "--";
        ///}
        ///     }
        /// </summary>
        public decimal PE
        {
            get
            {
                if (this.Income > 0)
                {
                    return this.CloseAmout / this.Income.Value;
                }
                else
                {
                    return 0;
                }


            }
        }

        /// <summary>
        /// 市净率
        /// 
        ///   if(data.mgjzc !=0)
        /// {
        ///         jQuery("#pb").html((收盘价/data.mgjzc).toFixed(2));
        ///         }
        /// else{
        ///           return "--"; 
        ///     }
        /// </summary>
        public decimal PB
        {
            get
            {
                if (this.Mgjzc > 0)
                {
                    return this.CloseAmout / this.Mgjzc.Value;
                }
                else
                {
                    return 0;
                }
            }
        }
    }
}
